<div class="row-fluid">
<div class="span3 visible-desktop">

</div>
<div class="span12 category">
	<div id="content">
		<div class="title"><h1 class="category-title">Related Post</h1></div>
		<div class="row-fluid">
			<div class="product-grid">
				<?php
					$mcid = @$_GET['cat_id'];
					if(!empty($mcid)) {
						$mcid = "cate.`parent_id`=$mcid AND";
					} else {
						$mcid  = '';
					}
					$sql = "SELECT DISTINCT pro.`id`, pro.`product_name`, img.`thumbnail`, price.`price` FROM tblproduct AS pro
							INNER JOIN tblproduct_in_category AS pcate ON pcate.`product_id`= pro.`id`
							INNER JOIN tblcategory AS cate ON cate.`id`= pcate.`category_id`
							INNER JOIN tblimage AS img ON img.`product_id`=pro.`id`
							INNER JOIN tblproduct_in_pharmacy AS price ON price.`product_id`=pro.`id`
							WHERE $mcid pro.`status`=1 AND price.`status`=1
							GROUP BY price.`product_id`
							ORDER BY RAND() LIMIT 8";
							$result = mysql_query($sql);
							if(dbNumRows($result)){
								$i = 1;
								while($row = mysql_fetch_assoc($result)){
								if ($i % 4 == 1) {
									echo '<div class="row-fluid box-product">';
								}
								$sql_img = "SELECT images FROM tblimage WHERE product_id = ".$row['id']." LIMIT 0,1";
								$result_img = mysql_query($sql_img);
								$row_img = mysql_fetch_assoc($result_img);
								$i++;
								$pharmacy=mysql_query("SELECT COUNT(DISTINCT pharmacy_id) AS pid
								FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']."");

								$price=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']." ORDER BY price ASC LIMIT 0,1");
								$myprice=mysql_fetch_assoc($price);
								$price1=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']." ORDER BY price DESC LIMIT 0,1");
								$myprice1=mysql_fetch_assoc($price1);
								if($row_img['images']!=""){
									$thumbnail_i = 	$row_img['images'];
								}else{
									$thumbnail_i = 'no-image-small.png';
								}
				?>
				<div class="span3 product_block">
                                    <?php 
                                    $data_pro = array(
                                        'id' =>$row['id'],
                                        'product_name' =>$row['product_name'],
                                        'product_name' =>$row['product_name'],
                                        'images' =>$thumbnail_i,
                                    );
                                    echo showProduct($data_pro, $myprice);?>
					<span class="label <?php echo ($data[Tblproduct::product_version] == 1) ? '' : 'label-warning'; ?> prodct-type"><?php echo ($data[Tblproduct::product_version] == 1) ? $lang['PRO_STATUS_USED'] : $lang['PRO_STATUS_NEW']; ?></span>
				</div>
		<?php
		}
		?>
		</div>
		<?php
	}
		?>
	</div>
	</div>
</div>
</div>